home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
proxy11.zip
/
BINTREE.PRX
next >
Wrap
Text File
|
1991-10-14
|
506b
|
17 lines
// sorting using binary search tree
// insert: struct x integer -> struct
// trav: struct
struct tree { value,left,right;}; // structure declaration
insert(tr,x) {if(tr=={}) return new tree(x,{},{});
if(x==tr.value) return tr;
if(x<tr.value) return new tree(tr.value,
insert(tr.left,x),tr.right);
return new tree(tr.value,tr.left,insert(tr.right,x));};
trav(x) {if(x != {}) {print(trav(x.left));
print(x.value);
print(trav(x.right));} };
end